home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / ftell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  513 b   |  32 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4.  
  5.     
  6. long ftell(fp)
  7. FILE *fp;
  8. {
  9.     long rv, count = fp->_cnt, adjust = 0;
  10.     unsigned int f = fp->_flag;
  11.     
  12.     if((count == 0) || (f & _IONBF) )
  13.     {
  14.     fflush(fp);    
  15.     rv = lseek(fp->_file, 0L, SEEK_CUR);
  16.     }
  17.     else
  18.     {
  19.     if(f & _IOREAD)
  20.         adjust = -count;
  21.     else if(f & (_IOWRT | _IORW))
  22.     {
  23.         if(f & _IOWRT)
  24.         adjust = count;
  25.     }
  26.     else return -1L;
  27.     
  28.     rv = lseek(fp->_file, 0L, SEEK_CUR);
  29.     }
  30.     return (rv < 0) ? -1L : rv + adjust;
  31. }
  32.